# import pandas as pd

# df = pd.read_csv('property-data.csv')

# print (df['NUM_BEDROOMS'])
# print (df['NUM_BEDROOMS'].isnull())


# import pandas as pd

# df = pd.read_csv('property-data.csv')

# new_df = df.dropna()

# print(new_df.to_string())


# import pandas as pd

# df = pd.read_csv('property-data.csv')

# df.fillna(12345, inplace = True)

# print(df.to_string())


# import pandas as pd

# df = pd.read_csv('property-data.csv')

# x = df["ST_NUM"].mean()

# df["ST_NUM"].fillna(x, inplace = True)

# print(df.to_string())


# import pandas as pd

# # 第三个日期格式错误
# data = {
#   "Date": ['2020/12/01', '2020/12/02' , '20201226'],
#   "duration": [50, 40, 45]
# }

# df = pd.DataFrame(data, index = ["day1", "day2", "day3"])

# df['Date'] = pd.to_datetime(df['Date'], format='mixed')

# print(df.to_string())


# import pandas as pd

# person = {
#   "name": ['Google', 'Runoob' , 'Taobao'],
#   "age": [50, 40, 12345]    # 12345 年龄数据是错误的
# }

# df = pd.DataFrame(person)

# df.loc[2, 'age'] = 30 # 修改数据

# print(df.to_string())
# import pandas as pd

# person = {
#   "name": ['Google', 'Runoob' , 'Taobao'],
#   "age": [50, 40, 12345]    # 12345 年龄数据是错误的
# }

# df = pd.DataFrame(person)

# for x in df.index:
#   if df.loc[x, "age"] > 120:
#     df.drop(x, inplace = True)

# print(df.to_string())


# import pandas as pd

# person = {
#   "name": ['Google', 'Runoob', 'Runoob', 'Taobao'],
#   "age": [50, 40, 40, 23]  
# }
# df = pd.DataFrame(person)

# print(df.duplicated())


# import pandas as pd

# # 示例数据
# data = {'Name': ['Alice', 'Bob', 'Charlie', None],
#         'Age': [25, 30, None, 35],
#         'City': ['New York', 'Los Angeles', 'Chicago', 'Houston']}

# df = pd.DataFrame(data)

# # 填充缺失的 "Age" 为均值
# df['Age'].fillna(df['Age'].mean(), inplace=True)

# print(df)


# import pandas as pd

# # 示例数据
# data = {'City': ['New York', 'Los Angeles', 'Chicago', 'Houston']}

# df = pd.DataFrame(data)

# # 对 "City" 列进行 One-Hot 编码
# df_encoded = pd.get_dummies(df, columns=['City'])

# print(df_encoded)


# from sklearn.preprocessing import StandardScaler
# import pandas as pd

# # 示例数据
# data = {'Age': [25, 30, 35, 40, 45],
#         'Salary': [50000, 60000, 70000, 80000, 90000]}

# df = pd.DataFrame(data)

# # 标准化数据
# scaler = StandardScaler()
# df_scaled = scaler.fit_transform(df)

# print(df_scaled)


import pandas as pd

# # 从 CSV 文件中读取数据
# df = pd.read_csv('data.csv')

# # 从 Excel 文件中读取数据
# df = pd.read_excel('data.xlsx')

# # 从 SQL 数据库中读取数据
# import sqlite3
# conn = sqlite3.connect('database.db')
# df = pd.read_sql('SELECT * FROM table_name', conn)

# # 从 JSON 字符串中读取数据
# json_string = '{"name": "John", "age": 30, "city": "New York"}'
# df = pd.read_json(json_string)

# # 从 HTML 页面中读取数据
# url = 'https://www.runoob.com'
# dfs = pd.read_html(url)
# df = dfs[0] # 选择第一个数据框


# import pandas as pd

# # 示例数据
# data = {'Name': ['Alice', 'Bob', 'Charlie', 'David'],
#         'Age': [25, 30, 35, 40],
#         'Salary': [50000, 60000, 70000, 80000]}

# df = pd.DataFrame(data)

# # 按照 "Age" 列的值进行降序排序
# df_sorted = df.sort_values(by='Age', ascending=False)
# print(df_sorted)



import pandas as pd
import numpy as np

# 创建示例数据
data = {
    '销售员': ['张三', '张三', '李四', '李四', '王五', '王五', '张三', '李四'],
    '地区': ['华东', '华北', '华东', '华北', '华东', '华北', '华东', '华北'],
    '产品': ['A', 'B', 'A', 'B', 'A', 'B', 'A', 'B'],
    '销售额': [100, 150, 120, 200, 90, 180, 110, 210]
}

df_sales = pd.DataFrame(data)

print("原始数据：")
print(df_sales)
print("---")

# 使用透视表对数据进行汇总
# 统计每个地区每个销售员的销售总额
pivot_table = pd.pivot_table(df_sales,
                             values='销售额',  # 要聚合的值
                             index='地区',     # 作为行的列
                             columns='销售员',   # 作为列的列
                             aggfunc=np.sum)  # 聚合函数，这里是求和

print("透视表结果：")
print(pivot_table)


